package com.bw.liuyushan.zhuangao4_mvptest1.MVP.View.ui;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bw.liuyushan.zhuangao4_mvptest1.R;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

/**
 * ZhuanGao4_MVPTest1
 * file name is : MyStand
 * created by Ender on 2021/8/19 17:34.
 * author : 刘雨杉
 * Describe(作用):自定义标准播放器
 * */
public class MyStand extends StandardGSYVideoPlayer {
    long time = 0;//定义时间变量
    public MyStand(Context context, Boolean fullFlag) {
        super(context, fullFlag);
    }

    public MyStand(Context context) {
        super(context);
    }

    public MyStand(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction()){//判断意图
            case MotionEvent.ACTION_DOWN://点击时
                if (time == 0){
                    time = System.currentTimeMillis();//获取当前点击的时间点
                    //单独直接点击红心图标 隐藏红心显示空心->取消喜欢
                    findViewById(R.id.xin22).setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            findViewById(R.id.xin22).setVisibility(GONE);
                            findViewById(R.id.xin11).setVisibility(VISIBLE);
                        }
                    });
                    //单独直接点击空心图标 隐藏空心显示红心->喜欢该视频
                    findViewById(R.id.xin11).setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            findViewById(R.id.xin11).setVisibility(GONE);
                            findViewById(R.id.xin22).setVisibility(VISIBLE);
                        }
                    });
                }else {
                    //当前时间-去之前点击的时间<**毫秒 判断状态为双击
                    if (System.currentTimeMillis()-time < 500){
                        //图像生成在鼠标 点击的那个点 (X,Y) 确定一个点的位置
                        ImageView imageView = new ImageView(getContext());
                        imageView.setX(event.getX());//X轴Y轴为鼠标点击的X,Y
                        imageView.setY(event.getY());//X轴Y轴为鼠标点击的X,Y
                        imageView.setImageDrawable(getContext().getDrawable(R.drawable.xin2));
                        imageView.setLayoutParams(new ViewGroup.LayoutParams(60,60));//图像参数 图像生成的大小
                        addView(imageView);
                        ObjectAnimator scaleX = ObjectAnimator.ofFloat(imageView, "scaleX", 1, 4);
                        ObjectAnimator scaleY = ObjectAnimator.ofFloat(imageView, "scaleY", 1, 4);
                        scaleX.setDuration(400);
                        scaleY.setDuration(400);
                        scaleX.start();
                        scaleY.start();
                        scaleX.addListener(new AnimatorListenerAdapter() {
                            @Override//缩放动画结束的时候↓
                            public void onAnimationEnd(Animator animation) {
                                super.onAnimationEnd(animation);
                                //消失动画
                                ObjectAnimator.ofFloat(imageView,"alpha",1,0).setDuration(200).start();
                            }
                        });
                        //双击出心同时 屏幕侧边红心亮起→喜欢视频效果
                        findViewById(R.id.xin11).setVisibility(GONE);
                        findViewById(R.id.xin22).setVisibility(VISIBLE);

                    }else {
                        time = System.currentTimeMillis();
                    }
                }
                break;
        }
        return super.onTouch(v, event);
    }


    @Override//双击暂停播放 与双击出心冲突 注释掉
    protected void touchDoubleUp(MotionEvent e) {
//        super.touchDoubleUp(e);
    }

    @Override//重新绑定自己的带红心布局
    public int getLayoutId() {
        return R.layout.mystand;
    }

}
